<%@page import="java.net.URLEncoder"%>
<%@page import="com.ldl.dto.Search"%>
<%@page import="com.ldl.vo.PageVO"%>
<%@page import="com.ldl.entity.Ldl"%>
<%@page import="java.util.List"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%--核心标签库 --%>
<head>
<title></title>
<jsp:include page="/admin/head.jsp"></jsp:include>
</head>
<body>
	<!-- 导航条 -->
	<jsp:include page="/admin/header.jsp"></jsp:include>
	<!--左边菜单-->
	<jsp:include page="/admin/left-menu.jsp"><jsp:param
			value="1" name="index" /></jsp:include>
	<!--底部-->
	<jsp:include page="/admin/footer.jsp"></jsp:include>

	<!--中间-->
	<section>
		<nav aria-label="breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item">管理首页</li>
				<li class="breadcrumb-item">系统中心</li>
				<li class="breadcrumb-item active">用户列表</li>
			</ol>
		</nav>
		<%
          Search search = (Search)request.getAttribute("search");
        %>

		<form class="form-inline">
			<div class="form-group mx-sm-1 mb-2">
				<label class="sr-only">用户姓名：</label> <select class="form-control">
					<option value="">全部</option>
					<option value="">男</option>
					<option value="">女</option>
				</select>
			</div>
			<div class="form-group mx-sm-1 mb-2">
				<label class="sr-only">关键字：</label> 
				<input type="text" class="form-control" placeholder="搜索关键字" name = "key" value="${search.key}">
			</div>
			<button type="submit" class="btn btn-primary mb-2" >
				<i class="fa fa-search"></i>
			</button>
			<a href="admin/ldl-add-form.jsp" class="btn btn-success ml-auto mr-2 mb-2"><i
				class="fa fa-plus"></i></a>
			<div class="form-group mx-sm-1 mb-2 pr-2">
				<label class="sr-only">数量：</label> 
				<select name="len" class="form-control">
					<%-- <option value="1" ${ requestScope.search.getPageSize()==1?"selected=\"selected\"":"" }>每页1条</option>
					<option value="5" ${ requestScope.search.getPageSize()==5?"selected=\"selected\"":"" }>每页5条</option>
					<option value="10" ${ requestScope.search.getPageSize()==10?"selected=\"selected\"":"" }>每页10条</option>
					<option value="20" ${ requestScope.search.getPageSize()==20?"selected=\"selected\"":"" }>每页20条</option> --%>
					<c:forEach begin="1" end="21" step="5" var="i">
					   <option value="${i }" 
					       <c:if test="${i== search.getPageSize()}">selected="selected"</c:if>>
					                   每页${i }条
					   </option>
					</c:forEach>
				</select>
			</div>
		</form>
		<div class="ml-2 mr-2">
			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th scope="col"></th>
						<th scope="col">ldl_id</th>
						<th scope="col">ldl_name</th>
						<th scope="col">ldl_birth</th>
						<th scope="col">ldl_sex</th>
						<th scope="col">ldl_age</th>
						<th scope="col">操作</th>
					</tr>
				</thead>
				<tbody>
					<%
				    //List<Ldl> list = (List<Ldl>) request.getAttribute("list");
					
					List<Ldl> list =(List<Ldl>) request.getAttribute("p");
									for (int i = 0; i < list.size(); i++) {
										Ldl u = list.get(i);
										request.setAttribute("i", i);
										request.setAttribute("u", u);
										
					%>
					<tr>
						<th scope="row">${requestScope.i+1}</th>
						<td>${requestScope.u.getLdlId() }</td>
						<td>${requestScope.u.getLdlName() }</td>
						<td>${requestScope.u.getLdlBirth() }</td>
						<td>${requestScope.u.getLdlSex() }</td>
						<td>${requestScope.u.getLdlAge() }</td>
						<td class="p-1"><div class="dropdown">
								<button
									class="btn btn-outline-primary btn-block dropdown-toggle"
									type="button" data-toggle="dropdown">操作</button>
								<div class="dropdown-menu dropdown-menu-right">
									<a class="dropdown-item" href="admin/ldl-seek.let?ldlId=${requestScope.u.getLdlId() }">查看</a>
									<a class="dropdown-item" href="admin/ldl-update-form.let?ldlId=${requestScope.u.getLdlId() }">修改</a>
									<a class="dropdown-item _delete"
										href="admin/ldl-delete.let?ldlId=${requestScope.u.getLdlId() }">删除</a>
								</div>
							</div></td>
					</tr>
					<%
						}
					%>
				</tbody>
			</table>
<%
String url = "admin/ldl-list.let?len={len}&current={current}&key={key}";
url = url.replace("{len}", search.getPageSize()+"");
int total = (int) request.getAttribute("total");
int len = search.getPageSize();
if(search.getKey()==null){
	url = url.replace("{key}", "");
}else{
	url = url.replace("{key}", URLEncoder.encode(search.getKey(), "UTF-8"));
}
%>

<ul class="pagination justify-content-center">
	<li class="page-item"><a class="page-link" href="<%=url.replace("{current}", "1")%>"> <span aria-hidden="true">&laquo;</span></a></li>
<%for(int i =1;i<=((total-1)/search.getPageSize()+1);i++) { %>
	<li class="page-item <%=search.getPageNumber().equals(i)?"active":""%>"><a class="page-link" href="<%=url.replace("{current}", i+"")%>"><%=i %></a></li>
<%} %>
	<li class="page-item"><a class="page-link" href="<%=url.replace("{current}", ((total-1)/len+1)+"")%>"> <span aria-hidden="true">&raquo;</span></a></li>
</ul>

		</div>
	</section>
	<div class="modal fade" id="confirmDialog" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">确认对话框</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        您确定要删除这条记录吗？
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
        <a href="#" class="btn btn-primary">确定</a>
      </div>
    </div>
  </div>
</div>  
	<script type="text/javascript">
		var numSelect = document.getElementById("numSelect");
		numSelect.onchange = function() {
			window.location = "admin/ldl-list.let?len=" + this.value;
		}
		
		$("._delete").on("click",function(){
			let $this = $(this);
			sys.confirm("您需要删除这条记录吗？",function(ret){
				if(ret){
					location = $this.attr("href");
				}
			});
			return false;
		});
	</script>
</body>
</html>
